package com.gitee.zhanyao.monomer.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 用户
 */
@Data
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler", "fieldHandler"})
@EntityListeners(AuditingEntityListener.class)
@Entity
@Table
public class SysUser implements Serializable {

    /**
     * 用户主键
     */
    @Id
    @GeneratedValue(generator = "uuidStrategy")
    @GenericGenerator(name = "uuidStrategy", strategy = "uuid")
    private String id;
    /**
     * 昵称
     */
    private String nickname;
    /**
     * 密码
     */
    private String password;
    /**
     * 姓名
     */
    private String username;
    /**
     * 手机号
     */
    private String mobile;
    /**
     * 电子邮箱
     */
    private String email;
    /**
     * 登录时间
     */
    private LocalDateTime loginTime;
    /**
     * 上次登录时间
     */
    private LocalDateTime lastLoginTime;
    /**
     * 登录次数
     */
    private Long count;
    /**
     * 失败尝试次数
     */
    private Integer failLoginCount;
    /**
     * 是否锁定
     */
    private Boolean isLock;
    /**
     * 系统编码
     */
    private String sysCode;
    /**
     * 创建时间
     */
    @CreatedDate
    @Column(updatable = false)
    private LocalDateTime createTime;
    /**
     * 创建人主键
     */
    private String createUserId = "";
    /**
     * 创建人姓名
     */
    private String createUserName = "";
    /**
     * 更新时间
     */
    @LastModifiedDate
    private LocalDateTime updateTime;
    /**
     * 更新人主键
     */
    private String updateUserId = "";
    /**
     * 更新人姓名
     */
    private String updateUserName = "";
    /**
     * 用户角色
     */
    @JsonIgnore
    @OneToMany(mappedBy = "sysUser", fetch = FetchType.LAZY)
    private List<SysUserRole> sysUserRoles;

}
